package com.oocl.ita.sakura.handler;

import java.io.ObjectOutputStream;

import com.oocl.ita.sakura.client.Client;
import com.oocl.ita.sakura.forwarder.Forwarder;
import com.oocl.ita.sakura.ioutil.NetIOUtil;
import com.oocl.ita.sakura.protocol.Protocol;
import com.oocl.ita.sakura.server.IMServer;

public class ChatHandler implements IHandler{

	@Override
	public void handle(Protocol protocol) {
		/*
		 * 1. 没有意义的字段： msgType from to content 
		 * 		pass
		 * 
		 * 2. 转发职能  : 转发chat 和shake 报文 
		 * 		发给 "to"
		 * 		报文封装：对原报文的改造 msgType from to content 都不变 
		 */
		
		// debug
		System.out.println("ChatHandler : " + Thread.currentThread().getName());
		System.out.println("ChatHandler : " + Thread.currentThread().getName() + protocol);
		
		// pre-process
		ObjectOutputStream oos = (ObjectOutputStream) Forwarder.threadlocaloos.get();
		String msgType = protocol.getMsgType();
		System.out.println("ChatHandler : " + Thread.currentThread().getName() + " MsgType : " + msgType);
		Client toClient = (Client) protocol.getParams().get("to");
		System.out.println("ChatHandler : " + Thread.currentThread().getName() + " toClient : " + toClient);

		// 封装报文
		// 什么都没改，原封不动发出去
		
		// 发送报文 给toClient
		NetIOUtil.send(protocol, toClient);
		
	}

}
